Meaning of the word "if you can't be good, be careful" in English

What does "if you can't be good, be careful" mean in English? Explore the meaning, pronunciation, and specific usage of this word with Lingoland.

if you can't be good, be careful

US /ɪf juː kænt biː ɡʊd, biː ˈker.fəl/
UK /ɪf juː kɑːnt biː ɡʊd, biː ˈkeə.fəl/
"if you can't be good, be careful" picture

Idiom

a humorous piece of advice suggesting that if you are going to do something immoral or illegal, you should at least make sure you don't get caught

Example:
I know you're going out tonight; just remember, if you can't be good, be careful.
He gave me a wink and said, 'If you can't be good, be careful.'